package me.wangshier.jms.taco.message.queue;

import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Author: tongqianwen
 * @Date: 2024/12/17
 */
public class ProducerConsumer {
    public static void main(String[] args) {
        // 队列容量
        int MAX_QUEUE_SIZE= 100;

        LinkedBlockingDeque<String> queue = new LinkedBlockingDeque<>(MAX_QUEUE_SIZE);
        Producer producer=new Producer(queue);
        Thread producerThread = new Thread(producer);
        producerThread.start();

        // 定义消费者线程大小
        int CONSUMER_THREAD_SIZE = 2;
        Thread[] consumerThreads = new Thread[CONSUMER_THREAD_SIZE];

        for (int i = 0; i < CONSUMER_THREAD_SIZE; i++) {
            Consumer consumer = new Consumer(queue);
            Thread consumerThread = new Thread(consumer, "Consumer-"+i);
            consumerThreads[i] = consumerThread;
            consumerThread.start();
        }
    }
}
